package com.spzx.test1.Day3Test;
/*
    并非全力
*/

import org.apache.commons.lang3.RandomUtils;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;



public class t2 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(7);

        for (int i = 1; i < 8; i++) {
            int finalI = i;
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "找到了第" + finalI + "颗龙珠");
                try {
                    TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,5));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                latch.countDown();
            }, "同学" + i).start();


        }


        System.out.println("七颗龙珠必需集齐才能释放线程");
        latch.await();
        System.out.println("龙珠集齐，释放线程");

    }


}
